﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0079)mhtml:file://E:\sve-air\documentacion\RandomNumberGenerator - Crypto++ Wiki.mht -->
<HTML lang=en 
dir=ltr><HEAD><TITLE>RandomNumberGenerator - Crypto++ Wiki</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6000.17080" name=GENERATOR><LINK href="/favicon.ico" 
rel="shortcut icon"><LINK title="Crypto++ Wiki (en)" 
href="/w/opensearch_desc.php" type=application/opensearchdescription+xml 
rel=search><LINK title="Crypto++ Wiki Atom feed" 
href="/w/index.php?title=Special:RecentChanges&amp;feed=atom" 
type=application/atom+xml rel=alternate><LINK media=screen 
href="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/shared.css" 
rel=stylesheet><LINK media=print 
href="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/commonPrint.css" 
rel=stylesheet><LINK media=screen 
href="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/main.css" 
rel=stylesheet><!--[if lt IE 5.5000]><link rel="stylesheet" href="/w/skins/monobook/IE50Fixes.css?270" media="screen" /><![endif]--><!--[if IE 5.5000]><link rel="stylesheet" href="/w/skins/monobook/IE55Fixes.css?270" media="screen" /><![endif]--><!--[if IE 6]><link rel="stylesheet" href="/w/skins/monobook/IE60Fixes.css?270" media="screen" /><![endif]--><!--[if IE 7]><LINK 
media=screen 
href="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/IE70Fixes.css" 
rel=stylesheet><![endif]--><LINK 
href="/w/index.php?title=MediaWiki:Common.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK media=print 
href="/w/index.php?title=MediaWiki:Print.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK 
href="/w/index.php?title=MediaWiki:Monobook.css&amp;usemsgcache=yes&amp;ctype=text%2Fcss&amp;smaxage=18000&amp;action=raw&amp;maxage=18000" 
rel=stylesheet><LINK 
href="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/index.css" 
rel=stylesheet>
<SCRIPT>
var skin="monobook",
stylepath="/w/skins",
wgUrlProtocols="http\\:\\/\\/|https\\:\\/\\/|ftp\\:\\/\\/|irc\\:\\/\\/|gopher\\:\\/\\/|telnet\\:\\/\\/|nntp\\:\\/\\/|worldwind\\:\\/\\/|mailto\\:|news\\:|svn\\:\\/\\/",
wgArticlePath="/wiki/$1",
wgScriptPath="/w",
wgScriptExtension=".php",
wgScript="/w/index.php",
wgVariantArticlePath=false,
wgActionPaths={},
wgServer="http://www.cryptopp.com",
wgCanonicalNamespace="",
wgCanonicalSpecialPageName=false,
wgNamespaceNumber=0,
wgPageName="RandomNumberGenerator",
wgTitle="RandomNumberGenerator",
wgAction="view",
wgArticleId=1498,
wgIsArticle=true,
wgUserName=null,
wgUserGroups=null,
wgUserLanguage="en",
wgContentLanguage="en",
wgBreakFrames=false,
wgCurRevisionId=3275,
wgVersion="1.16.0",
wgEnableAPI=true,
wgEnableWriteAPI=true,
wgSeparatorTransformTable=["", ""],
wgDigitTransformTable=["", ""],
wgMainPageTitle="Main Page",
wgFormattedNamespaces={"-2": "Media", "-1": "Special", "0": "", "1": "Talk", "2": "User", "3": "User talk", "4": "Crypto++ Wiki", "5": "Crypto++ Wiki talk", "6": "File", "7": "File talk", "8": "MediaWiki", "9": "MediaWiki talk", "10": "Template", "11": "Template talk", "12": "Help", "13": "Help talk", "14": "Category", "15": "Category talk"},
wgNamespaceIds={"media": -2, "special": -1, "": 0, "talk": 1, "user": 2, "user_talk": 3, "crypto++_wiki": 4, "crypto++_wiki_talk": 5, "file": 6, "file_talk": 7, "mediawiki": 8, "mediawiki_talk": 9, "template": 10, "template_talk": 11, "help": 12, "help_talk": 13, "category": 14, "category_talk": 15, "image": 6, "image_talk": 7},
wgSiteName="Crypto++ Wiki",
wgCategories=["Sample", "Random Number"],
wgRestrictionEdit=[],
wgRestrictionMove=[];
</SCRIPT>

<SCRIPT 
src="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/wikibits.js"></SCRIPT>

<SCRIPT 
src="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/ajax.js"></SCRIPT>

<SCRIPT 
src="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/index.php"></SCRIPT>
</HEAD>
<BODY 
class="mediawiki ltr ns-0 ns-subject page-RandomNumberGenerator skin-monobook">
<DIV id=globalWrapper>
<DIV id=column-content>
<DIV id=content><A id=top></A>
<H1 class=firstHeading id=firstHeading>RandomNumberGenerator</H1>
<DIV id=bodyContent>
<H3 id=siteSub>From Crypto++ Wiki</H3>
<DIV id=contentSub></DIV>
<DIV id=jump-to-nav>Jump to: <A 
href="http://www.cryptopp.com/wiki/RandomNumberGenerator#column-one">navigation</A>, 
<A 
href="http://www.cryptopp.com/wiki/RandomNumberGenerator#searchInput">search</A></DIV><!-- start content -->
<P>Crypto++ provides the following <STRONG 
class=selflink>RandomNumberGenerators</STRONG> when using the library. Some are 
Cryptographically secure, others are not. </P>
<TABLE class=toc id=toc>
  <TBODY>
  <TR>
    <TD>
      <DIV id=toctitle>
      <H2>Contents</H2></DIV>
      <UL>
        <LI class="toclevel-1 tocsection-1"><A 
        href="http://www.cryptopp.com/wiki/RandomNumberGenerator#Usage"><SPAN 
        class=tocnumber>1</SPAN> <SPAN class=toctext>Usage</SPAN></A> 
        <LI class="toclevel-1 tocsection-2"><A 
        href="http://www.cryptopp.com/wiki/RandomNumberGenerator#Pseudo_Random_Number_Generation"><SPAN 
        class=tocnumber>2</SPAN> <SPAN class=toctext>Pseudo Random Number 
        Generation</SPAN></A> 
        <UL>
          <LI class="toclevel-2 tocsection-3"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#LC_RNG"><SPAN 
          class=tocnumber>2.1</SPAN> <SPAN class=toctext>LC_RNG</SPAN></A> 
          <LI class="toclevel-2 tocsection-4"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#RandomPool"><SPAN 
          class=tocnumber>2.2</SPAN> <SPAN class=toctext>RandomPool</SPAN></A> 
          <LI class="toclevel-2 tocsection-5"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#AutoSeededX917RNG.3C_BlockCipher_.3E"><SPAN 
          class=tocnumber>2.3</SPAN> <SPAN class=toctext>AutoSeededX917RNG&lt; 
          BlockCipher &gt;</SPAN></A> 
          <LI class="toclevel-2 tocsection-6"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#AutoSeededRandomPool"><SPAN 
          class=tocnumber>2.4</SPAN> <SPAN 
          class=toctext>AutoSeededRandomPool</SPAN></A> </LI></UL>
        <LI class="toclevel-1 tocsection-7"><A 
        href="http://www.cryptopp.com/wiki/RandomNumberGenerator#Sample_Programs"><SPAN 
        class=tocnumber>3</SPAN> <SPAN class=toctext>Sample Programs</SPAN></A> 
        <UL>
          <LI class="toclevel-2 tocsection-8"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#LCG"><SPAN 
          class=tocnumber>3.1</SPAN> <SPAN class=toctext>LCG</SPAN></A> 
          <LI class="toclevel-2 tocsection-9"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#RandomPool_2"><SPAN 
          class=tocnumber>3.2</SPAN> <SPAN class=toctext>RandomPool</SPAN></A> 
          <LI class="toclevel-2 tocsection-10"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#AutoSeededX917RNG"><SPAN 
          class=tocnumber>3.3</SPAN> <SPAN 
          class=toctext>AutoSeededX917RNG</SPAN></A> 
          <LI class="toclevel-2 tocsection-11"><A 
          href="http://www.cryptopp.com/wiki/RandomNumberGenerator#AutoSeedeRandomPool"><SPAN 
          class=tocnumber>3.4</SPAN> <SPAN 
          class=toctext>AutoSeedeRandomPool</SPAN></A> 
  </LI></UL></LI></UL></TD></TR></TBODY></TABLE>
<SCRIPT>if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </SCRIPT>

<H2><SPAN class=mw-headline id=Usage>Usage </SPAN></H2>
<P>Wei Dai recommends <A class="external autonumber" 
href="http://groups.google.com/group/cryptopp-users/tree/browse_frm/thread/9e3e05f714c8795c/13159e5cc8536203">[1]</A> 
using a <A title=Generator 
href="http://www.cryptopp.com/wiki/Generator">Generator</A> on a per thread 
basis. Additionally, see <A class="external text" 
href="http://groups.google.com/group/cryptopp-users/browse_thread/thread/c751dc22113f32d4">WORKAROUND_MS_BUG_Q258000</A>. 
</P>
<H2><SPAN class=mw-headline id=Pseudo_Random_Number_Generation>Pseudo Random 
Number Generation </SPAN></H2>
<H3><SPAN class=mw-headline id=LC_RNG>LC_RNG </SPAN></H3>
<P><A class=mw-redirect title="LC RNG" 
href="http://www.cryptopp.com/wiki/LC_RNG">LC_RNG</A> is a <STRONG 
class=selflink>Linear Congruential</STRONG> <A class=mw-redirect title=RNG 
href="http://www.cryptopp.com/wiki/RNG">RNG</A>. Though this generator has no 
cryptographic value, it does allow one to reproduce results when debugging a 
program. Additionally, it is generally faster at generating a byte block (or 
stream). If one seeds the <A class=mw-redirect title=LCG 
href="http://www.cryptopp.com/wiki/LCG">LCG</A> with 0x00, a steady stream of 
0x80 is the result. Other seeds perform as expected. </P>
<H3><SPAN class=mw-headline id=RandomPool>RandomPool </SPAN></H3>
<P>The <A class=mw-redirect title=RandomPool 
href="http://www.cryptopp.com/wiki/RandomPool">RandomPool</A> behaves similar to 
an LCG in that the same seed produces the same results. However, unlike <A 
class=mw-redirect title="LC RNG" 
href="http://www.cryptopp.com/wiki/LC_RNG">LC_RNG</A>, the cipher behind the <A 
class=mw-redirect title=RandomPool 
href="http://www.cryptopp.com/wiki/RandomPool">RandomPool</A> is currently 
<CODE>MD5&lt;SHA&gt;</CODE>. From randpoool.cpp: </P><PRE>typedef MDC&lt;SHA&gt; RandomPoolCipher;</PRE>
<P>Then RandomPool would be initialized and used as follows: </P><PRE>// Must be at least 16 for RandomPool
const unsigned int SEEDSIZE = 16;
byte pcbSeed[ SEEDSIZE ];

// Scratch Area
const unsigned int BLOCKSIZE = 16 * 8;
byte pcbScratch[ BLOCKSIZE ];

...

// Random Pool Initalization
CryptoPP::RandomPool rng( SEEDSIZE );
rng.Put( pcbSeed, SEEDSIZE );
    
rng.GenerateBlock( pcbScratch, BLOCKSIZE );</PRE>
<H3><SPAN class=mw-headline 
id=AutoSeededX917RNG.3C_BlockCipher_.3E>AutoSeededX917RNG&lt; BlockCipher &gt; 
</SPAN></H3>
<P>Unlike <A class=mw-redirect title="LG RNG" 
href="http://www.cryptopp.com/wiki/LG_RNG">LG_RNG</A> and <A class=mw-redirect 
title=RandomPool href="http://www.cryptopp.com/wiki/RandomPool">RandomPool</A>, 
and does not require seed. However, one must specify an approved <A 
title="Block Cipher" href="http://www.cryptopp.com/wiki/Block_Cipher">Block 
Cipher</A> as a template parameter. </P><PRE>// Scratch Area
const unsigned int BLOCKSIZE = 16 * 8;
byte pcbScratch[ BLOCKSIZE ];

// Construction
CryptoPP::AutoSeededX917RNG&lt;CryptoPP::DES_EDE3&gt; rng;

// Random Block
rng.GenerateBlock( pcbScratch, BLOCKSIZE );</PRE>
<H3><SPAN class=mw-headline id=AutoSeededRandomPool>AutoSeededRandomPool 
</SPAN></H3>
<P>An <A class=mw-redirect title=AutoSeededRandomPool 
href="http://www.cryptopp.com/wiki/AutoSeededRandomPool">auto seeded random 
pool</A> was suggested by [?], which Wei later incorporated into Crypto++ with 
version [?]. The library uses either method below to seed the generator, 
depending on the Operating System. </P>
<UL>
  <LI>CryptGenRandom() by way of a Cryptographic Service Provider 
  <LI>/dev/random 
  <LI>/dev/urandom </LI></UL>
<P>For the Windows NT family, 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\RNG\Seed contains the latest 
seed value that the Windows Crypto API utilizes when generating a pseudo random 
block. </P><PRE>// Scratch Area
const unsigned int BLOCKSIZE = 16 * 8;
byte pcbScratch[ BLOCKSIZE ];

// Construction
CryptoPP::AutoSeededRandomPool rng;

// Random Block
rng.GenerateBlock( pcbScratch, BLOCKSIZE );</PRE>
<H2><SPAN class=mw-headline id=Sample_Programs>Sample Programs </SPAN></H2>
<H3><SPAN class=mw-headline id=LCG>LCG </SPAN></H3>
<P><A class=internal title=LCG.zip 
href="http://www.cryptopp.com/w/images/8/88/LCG.zip">LCG.zip</A> - Demonstrates 
using the Linear Congruential PRNG to generate pseudo random bytes </P>
<H3><SPAN class=mw-headline id=RandomPool_2>RandomPool </SPAN></H3>
<P><A class=internal title=RandomPool.zip 
href="http://www.cryptopp.com/w/images/6/65/RandomPool.zip">RandomPool.zip</A> - 
Demonstrates using a RandomPool to generate pseudo random bytes </P>
<H3><SPAN class=mw-headline id=AutoSeededX917RNG>AutoSeededX917RNG </SPAN></H3>
<P><A class=internal title=AutoSeededX917.zip 
href="http://www.cryptopp.com/w/images/d/d8/AutoSeededX917.zip">AutoSeededX917.zip</A> 
- Demonstrates using a AutoSeededX917RNG to generate pseudo random bytes </P>
<H3><SPAN class=mw-headline id=AutoSeedeRandomPool>AutoSeedeRandomPool 
</SPAN></H3>
<P><A class=internal title=ASRP.zip 
href="http://www.cryptopp.com/w/images/5/58/ASRP.zip">ASRP.zip</A> - 
Demonstrates using an AutoSeededRandomPool to generate pseudo random bytes </P><!-- 
NewPP limit report
Preprocessor node count: 79/1000000
Post-expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Expensive parser function count: 0/100
--><!-- Saved in parser cache with key crypto-wikicryptopp_:pcache:idhash:1498-0!1!0!!en!2!edit=0 and timestamp 20110217073433 -->
<DIV class=printfooter>Retrieved from "<A 
href="mhtml:file://E:\sve-air\documentacion\RandomNumberGenerator - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RandomNumberGenerator">http://www.cryptopp.com/wiki/RandomNumberGenerator</A>"</DIV>
<DIV class=catlinks id=catlinks>
<DIV id=mw-normal-catlinks><A title=Special:Categories 
href="http://www.cryptopp.com/wiki/Special:Categories">Categories</A>: <SPAN 
dir=ltr><A title=Category:Sample 
href="http://www.cryptopp.com/wiki/Category:Sample">Sample</A></SPAN> | <SPAN 
dir=ltr><A class=new title="Category:Random Number (page does not exist)" 
href="http://www.cryptopp.com/w/index.php?title=Category:Random_Number&amp;action=edit&amp;redlink=1">Random 
Number</A></SPAN></DIV></DIV><!-- end content -->
<DIV class=visualClear></DIV></DIV></DIV></DIV>
<DIV id=column-one>
<DIV class=portlet id=p-cactions>
<H5>Views</H5>
<DIV class=pBody>
<UL>
  <LI class=selected id=ca-nstab-main><A title="View the content page [c]" 
  accessKey=c 
  href="mhtml:file://E:\sve-air\documentacion\RandomNumberGenerator - Crypto++ Wiki.mht!http://www.cryptopp.com/wiki/RandomNumberGenerator">Page</A> 

  <LI class=new id=ca-talk><A title="Discussion about the content page [t]" 
  accessKey=t 
  href="http://www.cryptopp.com/w/index.php?title=Talk:RandomNumberGenerator&amp;action=edit&amp;redlink=1">Discussion</A> 

  <LI id=ca-viewsource><A 
  title="This page is protected.&#10;You can view its source [e]" accessKey=e 
  href="http://www.cryptopp.com/w/index.php?title=RandomNumberGenerator&amp;action=edit">View 
  source</A> 
  <LI id=ca-history><A title="Past revisions of this page [h]" accessKey=h 
  href="http://www.cryptopp.com/w/index.php?title=RandomNumberGenerator&amp;action=history">History</A> 
  </LI></UL></DIV></DIV>
<DIV class=portlet id=p-personal>
<H5>Personal tools</H5>
<DIV class=pBody>
<UL>
  <LI id=pt-login><A 
  title="You are encouraged to log in; however, it is not mandatory [o]" 
  accessKey=o 
  href="http://www.cryptopp.com/w/index.php?title=Special:UserLogin&amp;returnto=RandomNumberGenerator">Log 
  in / create account</A> </LI></UL></DIV></DIV>
<DIV class=portlet id=p-logo><A title="Visit the main page" 
style="BACKGROUND-IMAGE: url(http://www.cryptopp.com/w/images/0/0b/Logo-Steel.png)" 
href="http://www.cryptopp.com/wiki/Main_Page"></A></DIV>
<SCRIPT type=text/javascript> if (window.isMSIE55) fixalpha(); </SCRIPT>

<DIV class="generated-sidebar portlet" id=p-navigation>
<H5>Navigation</H5>
<DIV class=pBody>
<UL>
  <LI id=n-mainpage-description><A title="Visit the main page [z]" accessKey=z 
  href="http://www.cryptopp.com/wiki/Main_Page">Main page</A> 
  <LI id=n-portal><A 
  title="About the project, what you can do, where to find things" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Community_portal">Community 
  portal</A> 
  <LI id=n-currentevents><A 
  title="Find background information on current events" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Current_events">Current 
  events</A> 
  <LI id=n-recentchanges><A title="The list of recent changes in the wiki [r]" 
  accessKey=r href="http://www.cryptopp.com/wiki/Special:RecentChanges">Recent 
  changes</A> 
  <LI id=n-randompage><A title="Load a random page [x]" accessKey=x 
  href="http://www.cryptopp.com/wiki/Special:Random">Random page</A> 
  <LI id=n-help><A title="The place to find out" 
  href="http://www.cryptopp.com/wiki/Help:Contents">Help</A> 
</LI></UL></DIV></DIV>
<DIV class=portlet id=p-search>
<H5><LABEL for=searchInput>Search</LABEL></H5>
<DIV class=pBody id=searchBody>
<FORM id=searchform action=/w/index.php><INPUT type=hidden value=Special:Search 
name=title> <INPUT id=searchInput title="Search Crypto++ Wiki" accessKey=f 
type=search name=search> <INPUT class=searchButton id=searchGoButton title="Go to a page with this exact name if exists" type=submit value=Go name=go>&nbsp; 
<INPUT class=searchButton id=mw-searchButton title="Search the pages for this text" type=submit value=Search name=fulltext> 
</FORM></DIV></DIV>
<DIV class=portlet id=p-tb>
<H5>Toolbox</H5>
<DIV class=pBody>
<UL>
  <LI id=t-whatlinkshere><A title="List of all wiki pages that link here [j]" 
  accessKey=j 
  href="http://www.cryptopp.com/wiki/Special:WhatLinksHere/RandomNumberGenerator">What 
  links here</A> 
  <LI id=t-recentchangeslinked><A 
  title="Recent changes in pages linked from this page [k]" accessKey=k 
  href="http://www.cryptopp.com/wiki/Special:RecentChangesLinked/RandomNumberGenerator">Related 
  changes</A> 
  <LI id=t-specialpages><A title="List of all special pages [q]" accessKey=q 
  href="http://www.cryptopp.com/wiki/Special:SpecialPages">Special pages</A> 
  <LI id=t-print><A title="Printable version of this page [p]" accessKey=p 
  href="http://www.cryptopp.com/w/index.php?title=RandomNumberGenerator&amp;printable=yes" 
  rel=alternate>Printable version</A> 
  <LI id=t-permalink><A title="Permanent link to this revision of the page" 
  href="http://www.cryptopp.com/w/index.php?title=RandomNumberGenerator&amp;oldid=3275">Permanent 
  link</A> </LI></UL></DIV></DIV></DIV><!-- end of the left (by default at least) column -->
<DIV class=visualClear></DIV>
<DIV id=footer>
<DIV id=f-poweredbyico><A href="http://www.mediawiki.org/"><IMG height=31 
alt="Powered by MediaWiki" 
src="RandomNumberGenerator%20-%20Crypto++%20Wiki_archivos/mhtD2(1).tmp" 
width=88></A></DIV>
<UL id=f-list>
  <LI id=lastmod>This page was last modified on 5 March 2009, at 05:46. 
  <LI id=viewcount>This page has been accessed 7,186 times. 
  <LI id=privacy><A title="Crypto++ Wiki:Privacy policy" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:Privacy_policy">Privacy 
  policy</A> 
  <LI id=about><A title="Crypto++ Wiki:About" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:About">About Crypto++ 
  Wiki</A> 
  <LI id=disclaimer><A title="Crypto++ Wiki:General disclaimer" 
  href="http://www.cryptopp.com/wiki/Crypto++_Wiki:General_disclaimer">Disclaimers</A> 
  </LI></UL></DIV></DIV>
<SCRIPT>if (window.runOnloadHook) runOnloadHook();</SCRIPT>
<!-- Served in 0.400 secs. --></BODY></HTML>
